// ================================当鼠标划上去的时候1.先获取id值 然后return出来返回值 在调用ajax 访问后端实现交互--------
$("#nav-content-left a").mouseenter(
    SecondLevel,
            );
//========获取划上的每个a的id=====
function GetoID(){
     console.log(this.id) 
}
// =======================让首部2级子菜单的显示================================
function SecondLevel() {
    $("#nav-content-menubox").slideDown(500);
    var index = $(this).index();
    //2、根据序号，显示不同的子内容
    $("#nav-content-menubox>li").css({ "display": "none" });//让所有的li隐藏
    $("#nav-content-menubox>li:nth-child(" + (index + 1) + ")").css({ "display": "block" });

}
//=================吸顶效果=========================
window.onscroll = function () {
    // console.log(ord++);
    var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
    // console.log(scrollTop);
    if (scrollTop >= 50) {
        $("nav").css({
            "position": "fixed",
            "top": "0px",
            "z-index": 999
        });
        $("#bannerBox").css({
            "margin-top": 100
        });

    } else {
        $("nav").css({
            "position": "static"
        });

        $("#bannerBox").css({
            "margin-top": 20
        });
    }
}
//=====================让首页二级菜单隐藏=======================
$("nav").mouseleave(function () {
    //让菜单的面板隐藏
    $("#nav-content-menubox").slideUp(500);
});


//==============================传递cookie的值======================

function initUI() {
    let username = getCookie("username");
    if (username) {
        let htmlr="";
        htmlr=`欢迎:${username} <input id="btnLogout" type="button" value="注销" />`
        $("#usernameSpan").html(htmlr);
        $("#usernameSpan").css({
            "display": "block"
        });
        $("#loginBox").css({
            "display": "none"
        });
    } else {
        $("#loginBox").css({
            "display": "block"
        });
        $("#welcomeBox").css({
            "display": "none"
        });
    }
}

$(function(){
	initUI();
	$("#btnLogout").click(function(){
		removeCookie("username");
		initUI();
        $("#usernameSpan").css({
            "display": "none"
        });
	});
});
//=================用get请求往后端发送
    $(function () {
        $.get(
            "getGoodsList.php",
            { "typeId": "001" },
            function (data) {
            }, "json");   
    });